package com.sweet.controller;

import com.sweet.service.PayService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;


@RestController
@Slf4j
public class PayController {
    @Autowired
    private PayService payService;

    @Value("${server.port}")
    private String port;

    @GetMapping("/payment/hystrix/ok/{id}")
    public String paymentInfo_OK(@PathVariable("id") Integer id){
        String result = payService.paymentInfo_OK(id);
        log.info("*******result:"+result);
        return result;
    }

    @GetMapping("/payment/hystrix/timeout/{id}/{time}")
    public String paymentInfo_TimeOut(@PathVariable("id") Integer id,
                                      @PathVariable("time") Integer time){
        String result = payService.paymentInfo_TimeOut(id, time);
        log.info("*******result:"+result);
        return result;
    }

    @GetMapping("/payment/hystrix/error/{id}")
    public String paymentInfo_Error(@PathVariable("id") Integer id){
        String result = payService.paymentInfo_Error(id);
        log.info("*******result:"+result);
        return result;
    }

    @GetMapping("/payment/hystrix/break/{id}")
    public String paymentCircuitBreaker(@PathVariable("id") Integer id) {
        String result = payService.paymentCircuitBreaker(id);
        log.info("*******result:" + result);
        return result;
    }
}
